package com.yesido.javabase.concurrent.threadpool;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @author yuliang
 * @description jdk自带的线程池
 * @date 2021/6/20 16:57
 */
public class ThreadPoolTest {
    public static void main(String[] args) {


        /**
         * 核心线程无限
         * Integer.MAX_VALUE
         */
        ExecutorService service1 = Executors.newCachedThreadPool();

        /**
         * 10个核心 max也是10
         * 队列无限长 Integer.MAX_VALUE oom
         */
        ExecutorService service2 = Executors.newFixedThreadPool(10);
        /**
         * 单个线程的线程池
         * 队列无限大 Integer.MAX_VALUE oom
         */
        ExecutorService service3 = Executors.newSingleThreadExecutor();


       /*  public ScheduledThreadPoolExecutor(int corePoolSize) {
            super(corePoolSize, Integer.MAX_VALUE, 0, NANOSECONDS,
                    new ScheduledThreadPoolExecutor.DelayedWorkQueue());
        }*/
        /**
         * 最大线程数量Integer.MAX_VALUE
         * 创建大量线程 oom
         */
        ScheduledExecutorService service4 = Executors.newScheduledThreadPool(10);

        int a = 1;
        test(a);
        System.out.println(a);


        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        List<Integer> list1 = test1(list);
        System.out.println(list);
        System.out.println(list1);
        System.out.println(list==list1);//[1, 2, 3]

    }

    public static List<Integer> test1(List<Integer> list) {
        list.add(3);
        return list;

    }

    public static int test(int a) {
        a += 1;
        return a;
    }
}
